//
//  LeftTitle_NextView.m
//  Doctor
//
//  Created by 阳光 on 16/9/10.
//  Copyright © 2016年 阳光. All rights reserved.
//  左边文字右边箭头,而且点击后可跳转到下个界面

#import "LeftTitle_NextView.h"

@interface LeftTitle_NextView ()

@property(nonatomic,strong)UIButton *arrowBtn;

@end

@implementation LeftTitle_NextView

-(instancetype)initWithTitle:(NSString *)title hasNext:(BOOL)next
{
    if (self=[super init])
    {
        self.leftTitle=title;
        self.leftTitleLabel.textColor=Color333333;
        self.arrowBtn.hidden=NO;
        self.backgroundColor=WhiteColor;
    }
    return self;
}

// 预防
- (instancetype)init {
    if (self = [super init]) {
        NSAssert1(NO, @"%s  必须使用initWithTitle:方法初始化", __FUNCTION__);
    }
    return self;
}

- (UILabel *)leftTitleLabel
{
    if (!_leftTitleLabel) {
        _leftTitleLabel=[UILabel new];
        [self addSubview:_leftTitleLabel];
        [_leftTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.centerY);
            make.left.mas_equalTo(kmargin);
            make.width.mas_equalTo(150);
        }];
        _leftTitleLabel.font = [UIFont systemFontOfSize:13];
        _leftTitleLabel.text = _leftTitle;
    }
    return _leftTitleLabel;
}

-(UIButton *)arrowBtn
{
    if (!_arrowBtn) {
        _arrowBtn =[UIButton new];
        _arrowBtn.backgroundColor=ClearColor;
        [self addSubview:_arrowBtn];
        [_arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.leftTitleLabel);
            make.size.mas_equalTo(CGSizeMake(APPW,40));
        }];
        
        UIImageView *arrowImageView=[UIImageView new];
        arrowImageView.image=[UIImage imageNamed:@"cell_arrow"];
        [_arrowBtn addSubview:arrowImageView];
        [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kmargin*3/2,kmargin*3/2));
            make.right.mas_equalTo(-kmargin);
            make.centerY.mas_equalTo(self.leftTitleLabel.mas_centerY);
        }];
        
        // 按钮点击事件
        [_arrowBtn addTarget:self action:@selector(arrowBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _arrowBtn;
}

-(void)arrowBtnEvent:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(arrowBtnEvent:)])
    {
        [self.delegate arrowBtnEventWithUIButton:sender];
    }
}

@end
